package com.qst.mapreduce.wordcount.zuoyemywc.taobao0;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class App implements WritableComparable<App> {

    private int BrowseCount;
    private double CTR;

    //重写序列化write方法和重写反序列化readFields方法
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(BrowseCount);
        dataOutput.writeDouble(CTR);
    }
    public void readFields(DataInput dataInput) throws IOException {
        BrowseCount = dataInput.readInt();
        CTR = dataInput.readDouble();
    }
    public String toString(){
        return BrowseCount+","+CTR;
    }

    //重现WritableComparable接口的方法

    public int compareTo(App app) {
        if(this.BrowseCount>app.BrowseCount){
            return 1;
        }else if(this.BrowseCount<app.BrowseCount){
            return -1;
        }else{
            if(this.CTR>app.CTR){
                return 1;
            }else if(this.CTR<app.CTR){
                return -1;
            }else{
                return 0;
            }
       }
    }




    //getter和setter方法

    public int getBrowseCount() {
        return BrowseCount;
    }

    public void setBrowseCount(int browseCount) {
        BrowseCount = browseCount;
    }

    public double getCTR() {
        return CTR;
    }

    public void setCTR(double CTR) {
        this.CTR = CTR;
    }
}
